package fristphase.day9_15;

import java.util.*;

public class ListDome {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("one");
        list.add("two");
        list.add(0,"three");
        list.add("four");
        list.add("five");
        System.out.println(list);
        System.out.println(list.get(1));
        for (String str : list){
            System.out.print(str);
        }
        System.out.println("\n--------------1-------------");
        Iterator<String> it = list.iterator();//迭代器遍历不如for循环遍历
        while (it.hasNext()){
            System.out.print(it.next());
        }

        System.out.println("");
        for(String str : list){//for增强型遍历
            System.out.print(str);
        }
        System.out.println("\n--------------2-------------");
        String old = list.set(0,"one");//使用List类的set方法会返回被更改的值
        System.out.println("list="+list);
        System.out.println("old="+old);

        Collections.reverse(list);
        System.out.println(list);

        String old1 = list.remove(2);//使用List类的remove方法会返回被移除的值
        System.out.println(list);
        System.out.println(old1);
    }
}
